/**
 * <copyright>
 * </copyright>
 *
 * 
 */
package de.claaswilke.presents.resource.presents.mopp;

public class PresentsPrinter implements de.claaswilke.presents.resource.presents.IPresentsTextPrinter {
	
	protected de.claaswilke.presents.resource.presents.IPresentsTokenResolverFactory tokenResolverFactory = new de.claaswilke.presents.resource.presents.mopp.PresentsTokenResolverFactory();
	
	protected java.io.OutputStream outputStream;
	
	/**
	 * Holds the resource that is associated with this printer. This may be null if
	 * the printer is used stand alone.
	 */
	private de.claaswilke.presents.resource.presents.IPresentsTextResource resource;
	
	private java.util.Map<?, ?> options;
	private String encoding = System.getProperty("file.encoding");
	
	public PresentsPrinter(java.io.OutputStream outputStream, de.claaswilke.presents.resource.presents.IPresentsTextResource resource) {
		super();
		this.outputStream = outputStream;
		this.resource = resource;
	}
	
	protected int matchCount(java.util.Map<String, Integer> featureCounter, java.util.Collection<String> needed) {
		int pos = 0;
		int neg = 0;
		
		for (String featureName : featureCounter.keySet()) {
			if (needed.contains(featureName)) {
				int value = featureCounter.get(featureName);
				if (value == 0) {
					neg += 1;
				} else {
					pos += 1;
				}
			}
		}
		return neg > 0 ? -neg : pos;
	}
	
	protected void doPrint(org.eclipse.emf.ecore.EObject element, java.io.PrintWriter out, String globaltab) {
		if (element == null) {
			throw new java.lang.IllegalArgumentException("Nothing to write.");
		}
		if (out == null) {
			throw new java.lang.IllegalArgumentException("Nothing to write on.");
		}
		
		if (element instanceof de.claaswilke.presents.PresentGroup) {
			print_de_claaswilke_presents_PresentGroup((de.claaswilke.presents.PresentGroup) element, globaltab, out);
			return;
		}
		if (element instanceof de.claaswilke.presents.Person) {
			print_de_claaswilke_presents_Person((de.claaswilke.presents.Person) element, globaltab, out);
			return;
		}
		if (element instanceof de.claaswilke.presents.Conflict) {
			print_de_claaswilke_presents_Conflict((de.claaswilke.presents.Conflict) element, globaltab, out);
			return;
		}
		if (element instanceof de.claaswilke.presents.PastPresent) {
			print_de_claaswilke_presents_PastPresent((de.claaswilke.presents.PastPresent) element, globaltab, out);
			return;
		}
		if (element instanceof de.claaswilke.presents.PastPresentRule) {
			print_de_claaswilke_presents_PastPresentRule((de.claaswilke.presents.PastPresentRule) element, globaltab, out);
			return;
		}
		
		addWarningToResource("The printer can not handle " + element.eClass().getName() + " elements", element);
	}
	
	protected de.claaswilke.presents.resource.presents.mopp.PresentsReferenceResolverSwitch getReferenceResolverSwitch() {
		return (de.claaswilke.presents.resource.presents.mopp.PresentsReferenceResolverSwitch) new de.claaswilke.presents.resource.presents.mopp.PresentsMetaInformation().getReferenceResolverSwitch();
	}
	
	protected void addWarningToResource(final String errorMessage, org.eclipse.emf.ecore.EObject cause) {
		de.claaswilke.presents.resource.presents.IPresentsTextResource resource = getResource();
		if (resource == null) {
			// the resource can be null if the printer is used stand alone
			return;
		}
		resource.addProblem(new de.claaswilke.presents.resource.presents.mopp.PresentsProblem(errorMessage, de.claaswilke.presents.resource.presents.PresentsEProblemType.PRINT_PROBLEM, de.claaswilke.presents.resource.presents.PresentsEProblemSeverity.WARNING), cause);
	}
	
	public void setOptions(java.util.Map<?,?> options) {
		this.options = options;
	}
	
	public java.util.Map<?,?> getOptions() {
		return options;
	}
	
	public void setEncoding(String encoding) {
		if (encoding != null) {
			this.encoding = encoding;
		}
	}
	
	public String getEncoding() {
		return encoding;
	}
	
	public de.claaswilke.presents.resource.presents.IPresentsTextResource getResource() {
		return resource;
	}
	
	/**
	 * Calls {@link #doPrint(EObject, PrintWriter, String)} and writes the result to
	 * the underlying output stream.
	 */
	public void print(org.eclipse.emf.ecore.EObject element) throws java.io.IOException {
		java.io.PrintWriter out = new java.io.PrintWriter(new java.io.OutputStreamWriter(new java.io.BufferedOutputStream(outputStream), encoding));
		doPrint(element, out, "");
		out.flush();
		out.close();
	}
	
	public void print_de_claaswilke_presents_PresentGroup(de.claaswilke.presents.PresentGroup element, String outertab, java.io.PrintWriter out) {
		String localtab = outertab;
		// The printCountingMap contains a mapping from feature names to the number of
		// remaining elements that still need to be printed. The map is initialized with
		// the number of elements stored in each structural feature. For lists this is the
		// list size. For non-multiple features it is either 1 (if the feature is set) or
		// 0 (if the feature is null).
		java.util.Map<String, Integer> printCountingMap = new java.util.LinkedHashMap<String, Integer>(3);
		Object temp;
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__PERSONS));
		printCountingMap.put("persons", temp == null ? 0 : ((java.util.Collection<?>) temp).size());
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__CONFLICTS));
		printCountingMap.put("conflicts", temp == null ? 0 : ((java.util.Collection<?>) temp).size());
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__PAST_PRESENTS));
		printCountingMap.put("pastPresents", temp == null ? 0 : ((java.util.Collection<?>) temp).size());
		// print collected hidden tokens
		int count;
		boolean iterate = true;
		java.io.StringWriter sWriter = null;
		java.io.PrintWriter out1 = null;
		java.util.Map<String, Integer> printCountingMap1 = null;
		// DEFINITION PART BEGINS (CsString)
		out.print("Persons");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
		// DEFINITION PART BEGINS (CsString)
		out.print("{");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
		// DEFINITION PART BEGINS (CompoundDefinition)
		print_de_claaswilke_presents_PresentGroup_0(element, localtab, out, printCountingMap);
		iterate = true;
		while (iterate) {
			sWriter = new java.io.StringWriter();
			out1 = new java.io.PrintWriter(sWriter);
			printCountingMap1 = new java.util.LinkedHashMap<String, Integer>(printCountingMap);
			print_de_claaswilke_presents_PresentGroup_0(element, localtab, out1, printCountingMap1);
			if (printCountingMap.equals(printCountingMap1)) {
				iterate = false;
				out1.close();
			} else {
				out1.flush();
				out1.close();
				out.print(sWriter.toString());
				printCountingMap.putAll(printCountingMap1);
			}
		}
		// DEFINITION PART BEGINS (Containment)
		count = printCountingMap.get("persons");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__PERSONS));
			java.util.List<?> list = (java.util.List<?>) o;
			int index = list.size() - count;
			if (index >= 0) {
				o = list.get(index);
			} else {
				o = null;
			}
			if (o != null) {
				doPrint((org.eclipse.emf.ecore.EObject) o, out, localtab);
			}
			printCountingMap.put("persons", count - 1);
		}
		// DEFINITION PART BEGINS (CsString)
		out.print("}");
		out.print(" ");
		// DEFINITION PART BEGINS (LineBreak)
		out.println();
		out.print(localtab);
		// DEFINITION PART BEGINS (Containment)
		count = printCountingMap.get("conflicts");
		if (count > 0) {
			java.util.List<?> list = (java.util.List<?>)element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__CONFLICTS));
			int index  = list.size() - count;
			if (index < 0) {
				index = 0;
			}
			java.util.ListIterator<?> it  = list.listIterator(index);
			while (it.hasNext()) {
				Object o = it.next();
				doPrint((org.eclipse.emf.ecore.EObject) o, out, localtab);
			}
			printCountingMap.put("conflicts", 0);
		}
		// DEFINITION PART BEGINS (LineBreak)
		out.println();
		out.print(localtab);
		// DEFINITION PART BEGINS (Containment)
		count = printCountingMap.get("pastPresents");
		if (count > 0) {
			java.util.List<?> list = (java.util.List<?>)element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__PAST_PRESENTS));
			int index  = list.size() - count;
			if (index < 0) {
				index = 0;
			}
			java.util.ListIterator<?> it  = list.listIterator(index);
			while (it.hasNext()) {
				Object o = it.next();
				doPrint((org.eclipse.emf.ecore.EObject) o, out, localtab);
			}
			printCountingMap.put("pastPresents", 0);
		}
	}
	
	public void print_de_claaswilke_presents_PresentGroup_0(de.claaswilke.presents.PresentGroup element, String outertab, java.io.PrintWriter out, java.util.Map<String, Integer> printCountingMap) {
		String localtab = outertab;
		int count;
		// DEFINITION PART BEGINS (Containment)
		count = printCountingMap.get("persons");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PRESENT_GROUP__PERSONS));
			java.util.List<?> list = (java.util.List<?>) o;
			int index = list.size() - count;
			if (index >= 0) {
				o = list.get(index);
			} else {
				o = null;
			}
			if (o != null) {
				doPrint((org.eclipse.emf.ecore.EObject) o, out, localtab);
			}
			printCountingMap.put("persons", count - 1);
		}
		// DEFINITION PART BEGINS (WhiteSpaces)
		// DEFINITION PART BEGINS (CsString)
		out.print(",");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
	}
	
	
	public void print_de_claaswilke_presents_Person(de.claaswilke.presents.Person element, String outertab, java.io.PrintWriter out) {
		// The printCountingMap contains a mapping from feature names to the number of
		// remaining elements that still need to be printed. The map is initialized with
		// the number of elements stored in each structural feature. For lists this is the
		// list size. For non-multiple features it is either 1 (if the feature is set) or
		// 0 (if the feature is null).
		java.util.Map<String, Integer> printCountingMap = new java.util.LinkedHashMap<String, Integer>(1);
		Object temp;
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PERSON__IDENTIFIER));
		printCountingMap.put("identifier", temp == null ? 0 : 1);
		// print collected hidden tokens
		int count;
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("identifier");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PERSON__IDENTIFIER));
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("TEXT");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve((Object) o, element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PERSON__IDENTIFIER), element));
			}
			printCountingMap.put("identifier", count - 1);
		}
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
	}
	
	
	public void print_de_claaswilke_presents_Conflict(de.claaswilke.presents.Conflict element, String outertab, java.io.PrintWriter out) {
		String localtab = outertab;
		// The printCountingMap contains a mapping from feature names to the number of
		// remaining elements that still need to be printed. The map is initialized with
		// the number of elements stored in each structural feature. For lists this is the
		// list size. For non-multiple features it is either 1 (if the feature is set) or
		// 0 (if the feature is null).
		java.util.Map<String, Integer> printCountingMap = new java.util.LinkedHashMap<String, Integer>(2);
		Object temp;
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES));
		printCountingMap.put("conflictees", temp == null ? 0 : ((java.util.Collection<?>) temp).size());
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTOR));
		printCountingMap.put("conflictor", temp == null ? 0 : 1);
		// print collected hidden tokens
		int count;
		boolean iterate = true;
		java.io.StringWriter sWriter = null;
		java.io.PrintWriter out1 = null;
		java.util.Map<String, Integer> printCountingMap1 = null;
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("conflictor");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTOR));
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("TEXT");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve(getReferenceResolverSwitch() == null ? null : getReferenceResolverSwitch().getConflictConflictorReferenceResolver().deResolve((de.claaswilke.presents.Person) o, element, (org.eclipse.emf.ecore.EReference) element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTOR)), element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTOR), element));
			}
			printCountingMap.put("conflictor", count - 1);
		}
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
		// DEFINITION PART BEGINS (CsString)
		out.print("conflicts");
		out.print(" ");
		// DEFINITION PART BEGINS (CompoundDefinition)
		iterate = true;
		while (iterate) {
			sWriter = new java.io.StringWriter();
			out1 = new java.io.PrintWriter(sWriter);
			printCountingMap1 = new java.util.LinkedHashMap<String, Integer>(printCountingMap);
			print_de_claaswilke_presents_Conflict_0(element, localtab, out1, printCountingMap1);
			if (printCountingMap.equals(printCountingMap1)) {
				iterate = false;
				out1.close();
			} else {
				if (				printCountingMap1.get("conflictees")<1				) {
					iterate = false;
					out1.close();
				} else {
					out1.flush();
					out1.close();
					out.print(sWriter.toString());
					printCountingMap.putAll(printCountingMap1);
				}
			}
		}
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("conflictees");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES));
			java.util.List<?> list = (java.util.List<?>) o;
			int index = list.size() - count;
			if (index >= 0) {
				o = list.get(index);
			} else {
				o = null;
			}
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("TEXT");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve(getReferenceResolverSwitch() == null ? null : getReferenceResolverSwitch().getConflictConflicteesReferenceResolver().deResolve((de.claaswilke.presents.Person) o, element, (org.eclipse.emf.ecore.EReference) element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES)), element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES), element));
				out.print(" ");
			}
			printCountingMap.put("conflictees", count - 1);
		}
		// DEFINITION PART BEGINS (LineBreak)
		out.println();
		out.print(localtab);
	}
	
	public void print_de_claaswilke_presents_Conflict_0(de.claaswilke.presents.Conflict element, String outertab, java.io.PrintWriter out, java.util.Map<String, Integer> printCountingMap) {
		int count;
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("conflictees");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES));
			java.util.List<?> list = (java.util.List<?>) o;
			int index = list.size() - count;
			if (index >= 0) {
				o = list.get(index);
			} else {
				o = null;
			}
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("TEXT");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve(getReferenceResolverSwitch() == null ? null : getReferenceResolverSwitch().getConflictConflicteesReferenceResolver().deResolve((de.claaswilke.presents.Person) o, element, (org.eclipse.emf.ecore.EReference) element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES)), element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.CONFLICT__CONFLICTEES), element));
			}
			printCountingMap.put("conflictees", count - 1);
		}
		// DEFINITION PART BEGINS (WhiteSpaces)
		// DEFINITION PART BEGINS (CsString)
		out.print(",");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
	}
	
	
	public void print_de_claaswilke_presents_PastPresent(de.claaswilke.presents.PastPresent element, String outertab, java.io.PrintWriter out) {
		String localtab = outertab;
		// The printCountingMap contains a mapping from feature names to the number of
		// remaining elements that still need to be printed. The map is initialized with
		// the number of elements stored in each structural feature. For lists this is the
		// list size. For non-multiple features it is either 1 (if the feature is set) or
		// 0 (if the feature is null).
		java.util.Map<String, Integer> printCountingMap = new java.util.LinkedHashMap<String, Integer>(2);
		Object temp;
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__FROM));
		printCountingMap.put("from", temp == null ? 0 : 1);
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__TO));
		printCountingMap.put("to", temp == null ? 0 : ((java.util.Collection<?>) temp).size());
		// print collected hidden tokens
		int count;
		boolean iterate = true;
		java.io.StringWriter sWriter = null;
		java.io.PrintWriter out1 = null;
		java.util.Map<String, Integer> printCountingMap1 = null;
		// DEFINITION PART BEGINS (CsString)
		out.print("Past present");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
		// DEFINITION PART BEGINS (CsString)
		out.print("from");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("from");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__FROM));
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("TEXT");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve(getReferenceResolverSwitch() == null ? null : getReferenceResolverSwitch().getPastPresentFromReferenceResolver().deResolve((de.claaswilke.presents.Person) o, element, (org.eclipse.emf.ecore.EReference) element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__FROM)), element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__FROM), element));
				out.print(" ");
			}
			printCountingMap.put("from", count - 1);
		}
		// DEFINITION PART BEGINS (CsString)
		out.print("to");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
		// DEFINITION PART BEGINS (CompoundDefinition)
		iterate = true;
		while (iterate) {
			sWriter = new java.io.StringWriter();
			out1 = new java.io.PrintWriter(sWriter);
			printCountingMap1 = new java.util.LinkedHashMap<String, Integer>(printCountingMap);
			print_de_claaswilke_presents_PastPresent_0(element, localtab, out1, printCountingMap1);
			if (printCountingMap.equals(printCountingMap1)) {
				iterate = false;
				out1.close();
			} else {
				if (				printCountingMap1.get("to")<1				) {
					iterate = false;
					out1.close();
				} else {
					out1.flush();
					out1.close();
					out.print(sWriter.toString());
					printCountingMap.putAll(printCountingMap1);
				}
			}
		}
		// DEFINITION PART BEGINS (Containment)
		count = printCountingMap.get("to");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__TO));
			java.util.List<?> list = (java.util.List<?>) o;
			int index = list.size() - count;
			if (index >= 0) {
				o = list.get(index);
			} else {
				o = null;
			}
			if (o != null) {
				doPrint((org.eclipse.emf.ecore.EObject) o, out, localtab);
			}
			printCountingMap.put("to", count - 1);
		}
		// DEFINITION PART BEGINS (LineBreak)
		out.println();
		out.print(localtab);
	}
	
	public void print_de_claaswilke_presents_PastPresent_0(de.claaswilke.presents.PastPresent element, String outertab, java.io.PrintWriter out, java.util.Map<String, Integer> printCountingMap) {
		String localtab = outertab;
		int count;
		// DEFINITION PART BEGINS (Containment)
		count = printCountingMap.get("to");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT__TO));
			java.util.List<?> list = (java.util.List<?>) o;
			int index = list.size() - count;
			if (index >= 0) {
				o = list.get(index);
			} else {
				o = null;
			}
			if (o != null) {
				doPrint((org.eclipse.emf.ecore.EObject) o, out, localtab);
			}
			printCountingMap.put("to", count - 1);
		}
		// DEFINITION PART BEGINS (WhiteSpaces)
		// DEFINITION PART BEGINS (CsString)
		out.print(",");
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
	}
	
	
	public void print_de_claaswilke_presents_PastPresentRule(de.claaswilke.presents.PastPresentRule element, String outertab, java.io.PrintWriter out) {
		String localtab = outertab;
		// The printCountingMap contains a mapping from feature names to the number of
		// remaining elements that still need to be printed. The map is initialized with
		// the number of elements stored in each structural feature. For lists this is the
		// list size. For non-multiple features it is either 1 (if the feature is set) or
		// 0 (if the feature is null).
		java.util.Map<String, Integer> printCountingMap = new java.util.LinkedHashMap<String, Integer>(2);
		Object temp;
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__MULTIPLICATOR));
		printCountingMap.put("multiplicator", temp == null ? 0 : 1);
		temp = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__PERSON));
		printCountingMap.put("person", temp == null ? 0 : 1);
		// print collected hidden tokens
		int count;
		java.io.StringWriter sWriter = null;
		java.io.PrintWriter out1 = null;
		java.util.Map<String, Integer> printCountingMap1 = null;
		// DEFINITION PART BEGINS (CompoundDefinition)
		sWriter = new java.io.StringWriter();
		out1 = new java.io.PrintWriter(sWriter);
		printCountingMap1 = new java.util.LinkedHashMap<String, Integer>(printCountingMap);
		print_de_claaswilke_presents_PastPresentRule_0(element, localtab, out1, printCountingMap1);
		if (printCountingMap.equals(printCountingMap1)) {
			out1.close();
		} else {
			out1.flush();
			out1.close();
			out.print(sWriter.toString());
			printCountingMap.putAll(printCountingMap1);
		}
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("person");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__PERSON));
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("TEXT");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve(getReferenceResolverSwitch() == null ? null : getReferenceResolverSwitch().getPastPresentRulePersonReferenceResolver().deResolve((de.claaswilke.presents.Person) o, element, (org.eclipse.emf.ecore.EReference) element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__PERSON)), element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__PERSON), element));
				out.print(" ");
			}
			printCountingMap.put("person", count - 1);
		}
	}
	
	public void print_de_claaswilke_presents_PastPresentRule_0(de.claaswilke.presents.PastPresentRule element, String outertab, java.io.PrintWriter out, java.util.Map<String, Integer> printCountingMap) {
		int count;
		// DEFINITION PART BEGINS (PlaceholderUsingSpecifiedToken)
		count = printCountingMap.get("multiplicator");
		if (count > 0) {
			Object o = element.eGet(element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__MULTIPLICATOR));
			if (o != null) {
				de.claaswilke.presents.resource.presents.IPresentsTokenResolver resolver = tokenResolverFactory.createTokenResolver("NUMBER");
				resolver.setOptions(getOptions());
				out.print(resolver.deResolve((Object) o, element.eClass().getEStructuralFeature(de.claaswilke.presents.PresentsPackage.PAST_PRESENT_RULE__MULTIPLICATOR), element));
			}
			printCountingMap.put("multiplicator", count - 1);
		}
		// DEFINITION PART BEGINS (WhiteSpaces)
		out.print(" ");
	}
	
	
}
